@extends("layout.app")

@section("content")

    <div class="form-inline">

        <div class="form-group has-success">
            <input class="form-control" id="begin_time" placeholder="开始时间"/>
        </div>
        <div class="form-group has-success">
            <input class="form-control" id="end_time" placeholder="结束时间"/>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-default" onclick="jQuery('#rowed3').setGridParam({postData: postData()}).trigger('reloadGrid')"><i class="fa fa-search"></i> 查询</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-success" onclick="setDate('<?php echo date("Y-m-d", strtotime("Monday this week"))?>', '')"> 本周</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-info" onclick="setDate('<?php echo date("Y-m-d", strtotime("Monday this week")-604800)?>', '<?php echo date("Y-m-d", strtotime("last Sunday"))?>')"> 上周</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-warning" onclick="setDate('<?php echo date("Y-m-01")?>', '')"> 本月</button>
        </div>
        <div class="form-group has-success">
            &nbsp;<button id="button" class="btn btn-danger" onclick="setDate('<?php echo date("Y-m-01",  strtotime(date("Y-m-01") . " -1 month"))?>', '<?php echo date("Y-m-d",  strtotime(date("Y-m-01") . " -1 day"))?>')"> 上月</button>
        </div>
    </div>
    <div class="separator"></div>
    <div class="box-body">

        <table id="rowed3"></table>
        <div id="prowed3"></div>

    </div>
<script>

$(document).ready(function() {

	var data = {
        url :"/agent/zongdai/huobtk",
        colNames: ["时间","用户ID", "昵称","保险箱余额", "提现金额","合伙人","状态","备注"],
        colModel: [
            {
                name: "create_time",
                formatter:'date',
                    formatoptions: {srcformat: 'Y-m-d H:i:s', newformat: 'Y-m-d H:i:s'},
                    searchoptions: {
                        sopt: ['lt', 'le', 'gt', 'ge'],
                        dataInit : function (elem) {
                            $(elem).datepicker({
                                dateFormat: 'yy-mm-dd',
                                monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
                                dayNamesMin: ['日','一','二','三','四','五','六'] });
                        }
                    }
            },{
                name: "user_id",
                editable: true,
                key: true,
            }, {
                name: "nickname",
                sortable: false,
                search: false,
                formatter: function(cellvalue, options, object) {
                    cellvalue = cellvalue.toString();
                    return cellvalue+'(<a href="javascript:;" onclick="czmm('+object.user_id+')" data-toggle="modal" data-target="#fhModal2"><span class="text text-danger">重置密码</span></a>)';
                }
            }, {
                name: "money",
                sortable: false,
                search: false
            }, {
                name: "trans_money",
                sortable: false,
                search: false,
                formatter: function(cellvalue, options, object) {
                    return cellvalue/100;
                }
            },{
                name: 'zongdai',
                search: false,
                sortable: false,
            }, {
                name: "is_set",
                sortable: false,
                stype: 'select',
                searchoptions: {
                    sopt: ["eq", "ne"],
                    value: "0:审核中;1:通过;2:拒绝;3:余额不足"
                },
                formatter: function(cellvalue, options, object) {
                    cellvalue = cellvalue.toString();
                    switch (cellvalue) {
                        case "0":
                         return '<a href="javascript:;" onclick="rmb('+object.id+","+object.user_id+')" data-toggle="modal" data-target="#fhModal"><span class="text text-info">审核中</span></a>';
                        case "1":
                            return '<span class="text text-success">通过</span>';
                        case "3":
                            return '<span class="text text-error">保险箱余额不足</span>';
                    }
                    return '<span class="text text-danger">拒绝</span>';
                }
            }, {
                name: "desc",
                sortable: false,
                search: false,
                editable: true,
                edittype:'textarea',
            }],
        caption: '<i class="fa fa-list"></i> {{$label2}}',
        datatype: "json",
        sortname: "id",
        sortorder: "desc",
        autowidth: true
    };
	jqGrid(data, false, false, false);
$(".form-inline .form-control").datepicker({
        dateFormat: 'yy-mm-dd',
        monthNames: ['一月','二月','三月','四月','五月','六月','七月','八月','九月','十月','十一月','十二月'],
        dayNamesMin: ['日','一','二','三','四','五','六'] });

});
function rmb(id, user_id,rmb) {
    $("#rmbModalLabel").html("选择[用户Id: <span class='text-danger'>" + user_id + "</span>]的审核结果");
    $("#shid").val(id);
}

function czmm(user_id) {
    $("#rmbModalLabel2").html("重置[用户Id: <span class='text-danger'>" + user_id + "</span>]的密码为123456?");
    $("#mmrs").val(user_id);
}

function cz(){
    var user_id = $("#mmrs").val();
    $.post("/agent/zongdai/huobmm",{user_id: user_id}, function(result){
            if (result.success) {
                $.gritter.add({
                    text:result.message,
                    sticky: false,
                    time: '',
                    class_name: 'gritter-light'});

            } else {
                 $.gritter.add({
                    title: '错误信息',
                    text:result.message,
                    sticky: false,
                    time: ''});
            }
            $("#fhModal2").modal('hide');
        });
}
function sh(status){
    var id = $("#shid").val();
    var status = status;
    $.post("/agent/zongdai/huobsh",{id: id,status:status}, function(result){
            if (result.success) {
                $("#rowed3").trigger("reloadGrid");
                $.gritter.add({
                    text:result.message,
                    sticky: false,
                    time: '',
                    class_name: 'gritter-light'});

            } else {
                $("#rowed3").trigger("reloadGrid");
                 $.gritter.add({
                    title: '错误信息',
                    text:result.message,
                    sticky: false,
                    time: ''});
            }
            $("#fhModal").modal('hide');
        });
}
</script>
<div class="modal fade" id="fhModal" tabindex="-1" role="dialog" aria-labelledby="fhModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-name="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="rmbModalLabel"></h4>
            </div>
            <div class="modal-body">
                    <input type="hidden" name="id" id="shid"/>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" onclick="sh(1)"> 通过</button>
                <button type="button" class="btn btn-danger" onclick="sh(2)"> 拒绝</button>
                <button id="fh-cancel" type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
<div class="modal fade" id="fhModal2" tabindex="-1" role="dialog" aria-labelledby="fhModalLabel">
    <div class="modal-dialog" role="document">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-name="Close"><span aria-hidden="true">×</span></button>
                <h4 class="modal-title" id="rmbModalLabel2"></h4>
            </div>
            <div class="modal-body">
                    <input type="hidden" name="id" id='mmrs'/>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-success" onclick="cz()"> 重置</button>
                <button id="fh-cancel" type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
        </div>
    </div>
</div>
@endsection